package com.risetechnology.adapter;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.risetechnology.customviews.CustomFontTextView;
import com.risetechnology.data.Recipe;
import com.risetechnology.krystalkitchen1.R;

public class RecipeUpdateDetailAdapter extends ArrayAdapter<Recipe> {

	private Activity context;
	private int layoutId;
	private List<Recipe> data = null;
	private boolean isMasalas = false;

	public RecipeUpdateDetailAdapter(Activity context, int layoutId, List<Recipe> data) {
		super(context, layoutId, data);
		this.context = context;
		this.layoutId = layoutId;
		this.data = data;
	}

	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(layoutId, parent, false);

			holder = new ViewHolder();

			holder.imageviewIcon = (ImageView) convertView
					.findViewById(R.id.iv_image);
			holder.textviewIndex = (CustomFontTextView) convertView
					.findViewById(R.id.tv_index);
			holder.textviewName = (CustomFontTextView) convertView
					.findViewById(R.id.tv_name);
			holder.textviewServes = (CustomFontTextView) convertView
					.findViewById(R.id.tv_serves);
			holder.textviewMealType = (CustomFontTextView) convertView
					.findViewById(R.id.tv_main);
			holder.textviewDescription = (CustomFontTextView) convertView
					.findViewById(R.id.tv_main_description);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.textviewIndex.setText((position+1) + ".");
		holder.textviewName.setText(data.get(position).getName());
		holder.textviewServes.setText(data.get(position).getServes());
		String[] mealTypes = context.getResources().getStringArray(
				R.array.meal_types);
		holder.textviewMealType.setText(mealTypes[data.get(position)
				.getMealType()]);
		holder.textviewDescription.setText(data.get(position)
				.getMainDescription());

		holder.imageviewIcon.setImageDrawable(data.get(position).getImage());

		
		return convertView;
	}

	public boolean isMasalas() {
		return isMasalas;
	}

	public void setMasalas(boolean isMasalas) {
		this.isMasalas = isMasalas;
	}

	static class ViewHolder {
		ImageView imageviewIcon;
		TextView textviewName;
		TextView textviewIndex;
		TextView textviewServes;
		TextView textviewMealType;
		TextView textviewDescription;
	}

}
